<template>
    <div style="margin-top: -10px">
        <div style="border:1px solid #BFBFBF;padding: 10px;background-color: white;margin-top: 10px;height: 40px">
            <el-row :gutter="24">
                <el-col :span="2">
                    <span style="font-size: 19px;line-height:40px;margin-left: 5px">客户列表</span>
                </el-col>
                <el-col :span="7">
                    <span style="margin-left: 40px;">场景：</span>
                    <el-select v-model="value7" @change="changebusni" style="width: 150px;" placeholder="请选择">
                        <el-option
                                v-for="item in options"
                                :key="item.xz"
                                :label="item.label"
                                :value="item.xz">
                        </el-option>
                    </el-select>
                </el-col>
                <el-col :span="9">
                    <el-input placeholder="请输入客户名称" v-model="input3" @keyup.enter.native="initData" style="width: 250px;">
                        <i slot="suffix" class="el-input__icon el-icon-search" @click="initData"></i>
                    </el-input>
                </el-col>
            </el-row>
        </div>
        <div style="margin-top: 10px;border: 1px solid #BFBFBF;background-color: white">
            <div style="width: 100%;height: 40px;background-color: white;border-bottom: 1px solid #EBEEF5">
                <div class="operate" v-show="cjy">
                    <div class="selected—title" style="border-right: 1px; width: 200px; ">
                        场景：<span>{{value7}}</span>
                    </div>
                </div>
                <div class="operate" v-show="cje">
                    <div class="selected—title">
                        已选中<span class="selected—count">{{count}}</span>项
                    </div>
                    <div class="selected—title1">
                        <span><i class="el-icon-top-right"></i>转移</span>
                    </div>
                    <div class="selected—title2">
                        <span><i class="el-icon-edit-outline"></i>更改成交状态</span>
                    </div>
                    <div  class="selected—title2" >
                        <span><i class="el-icon-upload2"></i>导出选中</span>
                    </div>
                    <div  class="selected—title1">
                        <span><i class="el-icon-delete"></i>删除</span>
                    </div>
                </div>
            </div>
                <el-table
                        height="450"
                        :max-width="tableHeight2"
                        ref="multipleTable"
                        :data="clientList"
                        tooltip-effect="dark"
                        style="width: 100%;"
                        @selection-change="handleSelectionChange">
                    <el-table-column
                            prop="clientId"
                            type="selection"
                            width="80"
                            align="center">
                    </el-table-column>
                    <el-table-column
                            label="客户名称"
                            sortable
                            align="center"
                            width="300">
                        <template slot-scope="sp">
                            <a v-html="sp.row.clientName" class="businame" @click="todetails(sp.row)"></a>
                        </template>
                    </el-table-column>
                    <el-table-column
                            sortable
                            align="center"
                            prop="clientMobile"
                            label="电话"
                            width="180">
                    </el-table-column>
                    <el-table-column
                            sortable
                            align="center"
                            prop="clientSite"
                            label="地址"
                            width="350">
                    </el-table-column>
                    <el-table-column
                            sortable
                            align="center"
                            prop="clientPeople"
                            label="负责人"
                            width="170">
                    </el-table-column>
                    <el-table-column
                            label="操作"
                            align="center"
                            width="200">
                        <template>
                            <!--如果是三个标签，后两个标签padding-left: 10px;-->
                            <i style="font-size:18px;color: #409EFF" class="el-icon-edit"></i>
                            <i style="font-size:18px;padding-left: 20px;color: #409EFF" class="el-icon-delete"></i>
                        </template>
                    </el-table-column>
                </el-table>
        </div>
        <!--分页框-->
        <div style="margin-top: 15px;border: 1px solid #BFBFBF;padding: 10px;background-color: white">
            <div style="text-align: center">
                <el-pagination
                        @current-change="changePage"
                        :current-page.sync="currPage"
                        :page-sizes="[5, 10, 15, 20]"
                        :page-size="pageSize"
                        layout="total, sizes, prev, pager, next, jumper"
                        :total="totalSize"
                >
                </el-pagination>
            </div>
        </div>
    </div>
</template>

<script>
    export default {
        name: "TfyClientPage",
        data() {
            return {
                clientList: [],
                multipleTable: [],//存放选中值的数组
                isOne:true,//选中项为1就出现添加跟进记录和修改
                jilutankuan:false,
                multipleSelection: [],
                //场景一
                cjy:true,
                //场景二
                cje:false,
                value7: '',
                input3: '',
                options: [{
                    xz: '我负责的线索',
                    label: '我负责的线索'
                }, {
                    xz: '属下负责的线索',
                    label: '属下负责的线索'
                }, {
                    xz: '已转化的线索',
                    label: '已转化的线索'
                }, {
                    xz: '全部线索',
                    label: '全部线索'
                }],
                xz: '',

                options2: [{
                    value2: '导入',
                    label: '导入'
                }, {
                    value2: '导出',
                    label: '导出'
                }],
                value2:'',
                select: '',

                //页数
                //页数
                pageSize:5,//分页页大小
                currPage:1,//当前页码，默认为1
                totalSize:0,//总记录数
                //表格滚动条高度:max-height="tableHeight"
                tableHeight2: 1120,
                //快捷日期选择器
                pickerOptions: {
                    disabledDate(time) {
                        return time.getTime() > Date.now();
                    },
                    shortcuts: [{
                        text: '今天',
                        onClick(picker) {
                            picker.$emit('pick', new Date());
                        }
                    }, {
                        text: '昨天',
                        onClick(picker) {
                            const date = new Date();
                            date.setTime(date.getTime() - 3600 * 1000 * 24);
                            picker.$emit('pick', date);
                        }
                    }, {
                        text: '一周前',
                        onClick(picker) {
                            const date = new Date();
                            date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
                            picker.$emit('pick', date);
                        }
                    }]
                }
            }
        },
        methods: {
            initData(){


                window.console.log(this.input3);
                this.$axios.post("http://localhost:8088/client-list",this.qs.stringify(
                    {search:this.input3, page:this.currPage, size:this.pageSize}))
                    .then(v=>{
                        this.clientList = v.data.rows;
                        this.totalSize = v.data.total;
                    })
                    .catch()
            },
            changePage(v){
                this.currPage = v;
                this.initData();
            },
            /*跳转新增商机方法*/
            todetails(rows){
               this.$router.push({
                    path:"/business/addbusniess",
                    query: {
                        row:rows
                    }
                })
            },
            //复选框选中的
            handleSelectionChange(val) {
                this.multipleTable = val;//  this.multipleTable 选中的值
                if(this.multipleTable.length>0){
                    this.cjy=false;//第一行隐藏
                    this.cje=true;//批量操作栏出现
                }
                //选中项大于1不能执行添加跟进记录和修改按钮
                if(this.multipleTable.length>1){
                    this.isOne=false;
                }else if(this.multipleTable.length==0){//选中项为0时
                    this.cjy=true;//第一行出现
                    this.cje=false;//批量操作栏隐藏
                }else{
                    this.isOne=true;//添加跟进记录和修改出现
                }
                window.console.log(val);
            },
            toggleSelection(rows) {
                if (rows) {
                    rows.forEach(row => {
                        this.$refs.multipleTable.toggleRowSelection(row);
                    });
                } else {
                    this.$refs.multipleTable.clearSelection();
                }
            },
            gotoMenu(){
                this.$router.replace('/xjkh')
            },
            /*选择类型商机方法*/
            changebusni(){
                if(this.value7!=''){
                    this.seek=true;
                }
            },
        },
        computed:{
            count(){
                return this.multipleTable.length
            }
        },
        created: function () {
            this.initData(this.currPage, this.pageSize);
        },


        beforeRouteEnter(to, from, next) {
            console.log("****************Test2*********Enter*********");
            console.log(this, 'beforeRouteEnter'); // undefined
            console.log('to', to);
            console.log('from', from);
            console.log('next', next);
            console.log("客户页面")
            if(from.path=='/business/addbusniess'){
                from.meta.isUseCache = true;
            } else {
                from.meta.isBack = false;
            }


            /* if(from.name!='Dbusclient' && from.name!='Dproduct'){
                 if(sessionStorage.getItem('busName')){
                     sessionStorage.removeItem('busName')
                 }
                 if(sessionStorage.getItem('busWritten')){
                     sessionStorage.removeItem('busWritten')
                 }
                 if(sessionStorage.getItem('busPossibility')){
                     sessionStorage.removeItem('busPossibility')
                 }
                 if(sessionStorage.getItem('busMoney')){
                     sessionStorage.removeItem('busMoney')
                 }
                 if(sessionStorage.getItem('phaseId')){
                     sessionStorage.removeItem('phaseId')
                 }
                 if(sessionStorage.getItem('clientName')){
                     sessionStorage.removeItem('clientName')
                 }
                 if(sessionStorage.getItem('linkmanName')){
                     sessionStorage.removeItem('linkmanName')
                 }

             }*/
            next(vm => {
                //因为当钩子执行前，组件实例还没被创建
                // vm 就是当前组件的实例相当于上面的 this，所以在 next 方法里你就可以把 vm 当 this 来用了。
                console.log(vm);//当前组件的实例
            });
        },
    }
</script>

<style scoped>
    .block{
        position: fixed;
    }
    .operate{
        font-size: 12px;
        height: 40px;
        padding: 0 20px;
        color: #777;
        background: white;
    }
    .selected—title{
        margin-top: 15px;
        margin-left: -6px;
        border-right: 1px solid #e6e6e6;
        width: 86px;
        height:20px;
        float: left;
    }
    .selected—title1{
        margin-top: 15px;
        border-right: 1px solid #e6e6e6;
        width: 86px;
        height:20px;
        float: left;
        cursor: pointer;
    }
    .selected—title1 span{
        margin-left: 24px;
    }
    .selected—title1 span:hover{
        color:#409eff;
    }
    .selected—title2{
        margin-top: 15px;
        border-right: 1px solid #e6e6e6;
        width: 129px;
        height:20px;
        float: left;
        cursor: pointer;
    }
    .selected—title2 span{
        margin-left: 24px;
    }
    .selected—title2 span:hover{
        color:#409eff;
    }
    .businame{
        color: #409EFF;
        cursor:pointer;
    }
</style>